package cn.tedu.ou;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
public class GuanYu {

    private String name="关二爷";
    // 依赖关系由之前的具体的类型,修改为抽象的接口类型,实现解耦
    // 运行时Spring会从Spring容器中寻找Weapon接口的实现类对象来自动赋值给Weapon
    // 更换依赖对象,只需要维护保存在Spring容器中的Weapon实现类即可
    @Autowired
    @Qualifier("skyLance")
    private Weapon weapon;



    public void fight(){
        System.out.println(name+"使用"+weapon.getName()+"战斗");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Weapon getWeapon() {
        return weapon;
    }

    public void setWeapon(Weapon weapon) {
        this.weapon = weapon;
    }
}
